//
//  LS_CityTravelViewModel.m
//  breadPro
//
//  Created by 刘文超 on 2019/7/5.
//  Copyright © 2019 刘文超. All rights reserved.
//

#import "LS_CityTravelViewModel.h"
#import "LS_BannerModel.h"
#import "LS_CityTravelItemModel.h"
@interface LS_CityTravelViewModel()
@property(nonatomic,strong)id <LS_ViewModelService> services;
@end

@implementation LS_CityTravelViewModel
-(instancetype)initWithService:(id<LS_ViewModelService>)services
{
    if (self =[super init]) {
        _services = services;
        [self initialize];
    }return self;
}
-(void)initialize
{
    _travelData = [NSArray new];
    _bannerData = [NSArray new];
    _isSearch = NO;
    
    RACSignal *visibleSTateChanged = [RACObserve(self, isSearch) skip:1];
    
    [visibleSTateChanged subscribeNext:^(NSNumber
                                          *visible) {
        
        self->_isSearch = [visible boolValue];
    }];
    
    //获取数据
    _travelCommand = [[RACCommand alloc]initWithSignalBlock:^RACSignal *(id input) {
        return [[[self.services getCityTravelService] ls_requestCityTraveldataSignal:CityTravel_URL] doNext:^(id result) {
            NSLog(@"result--------%@",result);
            self.bannerData = [NSArray arrayWithArray:result[BannerDataKey]];
            self.travelData = [NSArray arrayWithArray:result[TravelDatakey]];
            
        }];
    }];
    
    
    _rightBarButtonItemCommand = [[RACCommand alloc]initWithSignalBlock:^RACSignal *(id input) {
        return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
           
            [subscriber sendNext:[NSNumber numberWithBool:self.isSearch]];
            [subscriber sendCompleted];
            return nil;
        }];
        
    }];
    _travelConnectionErrors = _travelCommand.errors;
    
}


@end
